package com.iwuke.dance.activity;

import android.content.Context;
import android.widget.RadioButton;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @author: 魏从响
 * @date: 2025/9/17
 */
public abstract class BaseFragment extends Fragment {
    protected boolean isVisible;
    public RadioButton radioButton;


//    /**
//     * 在这里实现Fragment数据的缓加载.
//     * @param isVisibleToUser
//     */
//    @Override
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        super.setUserVisibleHint(isVisibleToUser);
//        if(getUserVisibleHint()) {//当可见的时候执行操作
//            isVisible = true;
//            onVisible();
//        } else {//不可见时执行相应的操作
//            isVisible = false;
//            onInvisible();
//        }
//    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (hidden) {
            //不可见时执行相应的操作
            isVisible = false;
            onInvisible();
        }else {
            isVisible = true;
            onVisible();
        }
    }

    protected void onVisible(){
        lazyLoad();
    }
    protected abstract void lazyLoad();//子类实现
    protected void onInvisible(){}

    public void setLinearLayoutManager(Context context, RecyclerView recyclerView) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    public void setRadioButton(RadioButton radio_button) {

        radioButton = radio_button;
    }
}
